Don't panic because of invalid source
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 9 Aug 2016 13:11:20 +0000 (16:11 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 9 Aug 2016 13:11:20 +0000 (16:11 +0300)
src/cargo/core/source.rs
tests/bad-config.rs

index ed684e954685d721003f76b460950a39d9c03e9c..4a46c19294d26677af0d5842604bf1a935caf069 100644 (file)
@@ -131,7 +131,7 @@ impl SourceId {
     pub fn from_url(string: &str) -> CargoResult<SourceId> {
         let mut parts = string.splitn(2, '+');
         let kind = parts.next().unwrap();
-        let url = parts.next().unwrap();
+        let url = try!(parts.next().ok_or(human(format!("invalid source `{}`", string))));
 
         match kind {
             "git" => {
index ef1912d4728973f09f19983ad3802acf905a7317..9e6aad274ccbbe9010b74847a39de9234ffd5e56 100644 (file)
@@ -280,6 +280,45 @@ Caused by:
 "));
 }
 
+#[test]
+fn bad_source_in_cargo_lock() {
+    Package::new("foo", "0.1.0").publish();
+
+    let p = project("bar")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "bar"
+            version = "0.0.1"
+            authors = []
+
+            [dependencies]
+            foo = "0.1.0"
+        "#)
+        .file("src/lib.rs", "")
+        .file("Cargo.lock", r#"
+            [root]
+            name = "bar"
+            version = "0.0.1"
+            dependencies = [
+             "foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+            ]
+
+            [[package]]
+            name = "foo"
+            version = "0.1.0"
+            source = "You shall not parse"
+        "#);
+    p.build();
+
+    assert_that(p.cargo("build").arg("--verbose"),
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse lock file at: [..]
+
+Caused by:
+  invalid source `You shall not parse` for the key `package.source`
+"));
+}
+
 #[test]
 fn bad_git_dependency() {
     let foo = project("foo")